// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import VueRouter from 'vue-router'
import ElementUI from 'element-ui'
import request from './request'
import Vuex from 'vuex'
import 'element-ui/lib/theme-default/index.css'
import './assets/customize.scss'

Vue.config.productionTip = false
Vue.prototype.$request = request
Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)

router.beforeEach((to, from, next) => {
  // NProgress.start()
  if (to.path === '/login' || to.path === '/register') {
    request.token('')
  }
  let user = request.token()
  if (!user && to.path !== '/login' && to.path !== '/register') {
    next({ path: '/login' })
  } else {
    next()
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
